<template>
<!-- 使用 :to 属性实现组件之间的跳转 -->
  <van-cell
  class="article-item"
  :to="{
    name: 'article',
    params: {
      articleId: article.art_id
    }
  }"
  >
    <!-- 使用Cell单元格 组件循环遍历数据 -->
    <div
      slot="title"
      class="title van-multi-ellipsis--l2"
    >{{ article.title }}</div>
    <div slot="label">
      <div
        class="cover-wrap"
        v-if="article.cover.type === 3"
      >
        <div
          class="cover-item"
          v-for="(img, index) in article.cover.images"
          :key="index"
        >
          <van-image
            fit="cover"
            class="cover-item-img"
            :src="img"
          />
        </div>
      </div>
      <!-- 文章信息 -->
      <div class="label-info-wrap">
        <span>{{ article. aut_name }}</span>
        <span>{{ article.comm_count }}评论</span>
        <span>{{ article.pubdate | relativeTime}}</span>
      </div>
    </div>
    <!-- 判断当 对象里type 属性里有图片时 并且为一时渲染图片 -->
    <van-image
      slot="default"
      fit="cover"
      v-if="article.cover.type === 1"
      class="right-cover"
      :src="article.cover.images[0]"
    />
  </van-cell>
</template>

<script>
export default {
  name: 'ArticleItem',
  props: {
    article: {
      typeof: Object,
      required: true
    }
  }
}
</script>

<style lang="less" scoped>
.article-item {
  .title {
    font-size: 32px;
    color: #3a3a3a;
  }

  .van-cell__title {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
  // 右侧的一张图片
  .van-cell__value {
    // https://developer.mozilla.org/zh-CN/docs/Web/CSS/flex
    flex: unset;
    // unset
    // 属性是默认继承属性，该值等同于 inherit
    // 该属性是非继承属性，该值等同于 initial
    width: 232px;
    height: 146px;
    padding-left: 25px;
  }

  .right-cover {
    width: 100%;
    height: 146px;
  }

  .label-info-wrap span {
    font-size: 22px;
    color: #b4b4b4;
    margin-right: 25px;
  }

  .cover-wrap {
    display: flex;
    padding: 30px 0;
    .cover-item {
      flex: 1;
      height: 146px;
      &:not(:last-child) {
        padding-right: 4px;
      }
      .cover-item-img {
        width: 100%;
        height: 146px;
      }
    }
  }
}
</style>
